#pragma once

namespace fly {

	namespace jld{

		namespace pool
		{

			class io_service_pool
				:protected singleton<io_service_pool>
			{
				friend class singleton<io_service_pool>;
			private:
				typedef boost::shared_ptr<boost::asio::io_service> io_service_ptr;
				typedef boost::shared_ptr<boost::asio::io_service::work> work_ptr;
				explicit io_service_pool(size_t size = 4);
				~io_service_pool();
				std::vector<io_service_ptr> io_services_;

				std::vector<work_ptr> works_;

				std::size_t next_io_service_;
			public:
				void set_size(size_t size);
				void run();
				void stop();
				asio::io_service& get_io_service();
			};
			#define is_pool singleton<io_service_pool>::instance()
		}
	}
}
